#include "fileOperationsHeader.h"
char* removeFile(char path[])
{
	if(mh==NULL)
		return ERR_VFS_REMOVEFILE_02;
	FILE *fp=fopen(mh->fileSystemLabel,"r+b");
	int currentFileDescriptors=mh->countOfFileDescriptors;
	int maxFileDescriptors=mh->maxDescriptors;
	int noOfBlocks=maxFileDescriptors/2;
	int iterDescriptors=0;
	descriptors *d=(descriptors*)malloc(sizeof(descriptors));
	d=(descriptors*)searchBST(path);
	if(d==NULL)
		return ERR_VFS_REMOVEFILE_01;
	iterDescriptors=0;
	int fdIter=0;
	while(iterDescriptors<maxFileDescriptors)
	{
		if(strcmp(h->desc[iterDescriptors].location,d->location)==0 && strcmp(h->desc[iterDescriptors].fileName,d->fileName)==0 && h->desc[iterDescriptors].type=='f')
		{
			fdIter=iterDescriptors;
			break;
		}
		iterDescriptors++;
	}
	if(iterDescriptors==maxFileDescriptors)
		return ERR_VFS_REMOVEFILE_01;
	d->type='r';
	d->size=-1;
	h->desc[fdIter]=*d;
	h->freeList[d->blockNumber]='0';
	fseek(fp,(int)arr[d->blockNumber],SEEK_SET);
	int *currentBlock=(int*)malloc(maxBlockSize);
	fwrite(currentBlock,maxBlockSize,1,fp);
	mh->countOfFileDescriptors=mh->countOfFileDescriptors-1;
	fclose(fp);
	int bstRet=insertBSTWhileMount(maxFileDescriptors,h->desc);
	if(bstRet!=0)
		return "FAILURE <while creating BST>";
	int nAryRet=createnAryTree(maxFileDescriptors,h->desc);
	if(nAryRet!=0)
		return "FAILURE <while creating nAryTree>";
	int hashTableRet=hashTableMethod(h->desc,maxFileDescriptors);
	if(hashTableRet!=0)
		return "FAILURE <while creating hashTable>";
	return "SUCCESS";
}
